﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using DelonixRegiaHotel.Classes;
using System.Configuration;
using System.Collections;

namespace DelonixRegiaHotel.DBManager
{
    class LoginDBManager
    {
        public static Staff CheckLogin(Staff s)
        {
            Staff temp = new Staff();

            SqlConnection conn = null;
            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "Select * from Staff where staffID=@staffID and password=@password";
                comm.Parameters.AddWithValue("@staffID", s.StaffID);
                comm.Parameters.AddWithValue("@password", s.Password);
                SqlDataReader dr = comm.ExecuteReader();
                if (dr.Read())
                {
                    temp.AccessLevel = Convert.ToInt32(dr["accessLevel"]);
                    temp.StaffID = Convert.ToString(dr["staffID"]);
                }

                conn.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return temp;
        }








    }
}
